const { execSync } = require('child_process');
const micromatch = require('micromatch');

module.exports = {
    '*.js': (files) => {
        const branchName = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();
        console.log('当前分支为:', branchName);
        if (/^(gray|t\d+|master)$/.test(branchName)) {
            process.exit(0);
        }

        // app 目录下的文件不检测
        const needChekFiles = micromatch.not(files, [
            '**/res/**/*',
            '**/app/**/*',
            '**/src/modules/Touch/**/*',
            '**/src/views/newRecommend/viewWin/index.js',
            '**/src/views/newRecommend/detail/viewWin/index.js',
            '**/app-wpt/src/components/WxPayModal/md5.js',
        ]);

        if (needChekFiles.length > 0) {
            return [`eslint ${needChekFiles.join(' ')} --fix`, `prettier ${needChekFiles.join(' ')} --write`];
        } else {
            return [];
        }
    },
    '*.less': ['prettier --parser=less --write'],
};
